<?php

class ToolsModule extends CWebModule
{
	public $homeUrl = array('/tools');
	public $defaultController = 'merchant';

	public function init()
	{
		// import the module-level models and components
		$this->setImport(array(
			'tools.models.*',
			'tools.components.*',
		));
		$this->layout = 'webroot.themes.'.Yii::app()->theme->name.'.views.layouts.layout-tools';
		// reset the errorHandler. PS: only this way works.
		$components = array(
			'errorHandler' => array(
					'errorAction' => 'tools/default/error',
			),
			'user' => array(
				'allowAutoLogin' => true,
                'class' => 'CWebUser',
                'loginUrl' => Yii::app()->createUrl('tools/default/login'),
            )
		);
		Yii::app()->setComponents($components);
		$this->setComponents($components);  // add these components to this instance
		
		Yii::app()->user->setStateKeyPrefix('_tools');
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		}
		else
			return false;
	}
}
